package com.looookme.shaozhuo.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

/**
 * Created by Shaozhuo on 2015/9/8.
 */
public class ActivityForResult_2 extends Activity {
    private static final int RESULT = 0x22;
    private String SUM = "";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        SUM += bundle.getString("NUM_1");
        SUM += bundle.getString("NUM_2");

        initData();
    }

    private void initData() {
        LinearLayout ll = new LinearLayout(this);
        ll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ll.setOrientation(LinearLayout.VERTICAL);
        setContentView(ll);

        Button forback = new Button(this);
        forback.setText("返回");
        forback.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        forback.setTextSize(24);
        ll.addView(forback);

        forback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(ActivityForResult_2.this, ActivityForResult.class);
                Bundle bundle = new Bundle();
                bundle.putString("RESULT", SUM);
                intent.putExtras(bundle);

                setResult(RESULT, intent);
                finish();
            }
        });
    }
}
